package com.lujianfei.mqtt.ktx

import com.google.gson.Gson

/**
 * @Author: wn
 * @Date: 2024/4/23 9:14
 * @Description: 扩展函数
 */

/**
 * String  转 data class
 */
inline fun <reified T : Any> String.toDataClass(): T? =
  kotlin.runCatching {
    Gson().fromJson(this, T::class.java)
  }.getOrNull()


/**
 * data class 转 String
 */
inline fun <reified T : Any> T.toJsonString(): String? =
  kotlin.runCatching {
    Gson().toJson(this)
  }.getOrNull()
